DEW.Sidebar = Backbone.View.extend({

    template: Handlebars.templates['sidebar'],
    
    currentCategoryId: 0,

    events: {
        "click .category_link" : "changeCategory"
    },

    initialize: function() {
        //Aqui se puede poner configuracion inicial
        this.listenTo(this.model, 'reset',  this.render);
    },

    render: function() {
        var me = this;
        var categories = _.map(this.model.toJSON(),function(model) {
            model.active = me.currentCategoryId === model.id;
            return model;
        });
        this.$el.html(this.template({
            categories: categories
        }));
    },

            //Algun parametro que le querramos configurar
     changeCategory: function(e) {
        e.preventDefault();
        this.currentCategoryId = parseInt($(e.target).attr("data-id"));
        this.render();
        this.trigger("changeCategory",this.currentCategoryId);
    }
});